﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Elective1_kim_sequel
{
    public partial class Form_Log_in : Form
    {
        public Form_Log_in()
        {
            InitializeComponent();
            btn_login.Click += new EventHandler(btn_login_Click);       
            btn_cancel.Click += new EventHandler(btn_cancel_Click);
            btn_Exit.Click += new EventHandler(btn_Exit_Click);
        }

        void btn_Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

   

        void btn_cancel_Click(object sender, EventArgs e)
        {
            
            Employee._AccessLevel = Employee.AccessLevel.User;
        }


 

        void btn_login_Click(object sender, EventArgs e)
        {
            string user = txt_user.Text.ToString();
            string pwd = txt_pwd.Text.ToString();
            if (user.Trim() != "")
            {
                DataTable tb = Database.Table("SELECT * FROM tbl1 WHERE User_Name='" + user + "' AND Password='" + pwd + "'");
                if (tb.Rows.Count > 0)
                {
                    if (tb.Rows[0]["AccessLevel"].ToString() == "1")
                    {
                        Employee._AccessLevel = Employee.AccessLevel.Admin;
                    }
                    Employee.IdNumber = tb.Rows[0]["ID"].ToString();
                    Form_Main form_Main = new Form_Main();
                    form_Main.Show();
                    this.Hide();
                }
                else 
                {
                    MessageBox.Show("Invalid Username or Paswword", "OOPS!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }            
        }

       
    }
}
